package payment

import (
	"fmt"

	. "go-share/models"
)

type Coupon struct {
	Tactic   float32 // 锦襄
	Report   float32 // 研报
	Class    float32 // 课堂
	Strategy float32 // 量化策略
}

// 优惠信息数据结构
var couponHash map[int]Coupon = map[int]Coupon{
	MEMBER_GROUP_WEIGHT_VIP0: {Tactic: 1, Report: 1, Class: 1, Strategy: 1},
	MEMBER_GROUP_WEIGHT_VIP1: {Tactic: 0.9, Report: 1, Class: 0.9, Strategy: 1},
	MEMBER_GROUP_WEIGHT_VIP2: {Tactic: 0.9, Report: 0.8, Class: 0.9, Strategy: 1},
	MEMBER_GROUP_WEIGHT_VIP3: {Tactic: 0.8, Report: 0, Class: 0.85, Strategy: 1},
}

var VIPLevel map[int]string = map[int]string{
	MEMBER_GROUP_WEIGHT_VIP0: "免费",
	MEMBER_GROUP_WEIGHT_VIP1: "VIP1",
	MEMBER_GROUP_WEIGHT_VIP2: "VIP2",
	MEMBER_GROUP_WEIGHT_VIP3: "VIP3",
}

func GetCoupon(ref_type int, groupWeight int) (float32, string, error) {
	coupon, ok := couponHash[groupWeight]
	var comment string
	if !ok {
		return 1.0, fmt.Sprintf("暂时不享受折扣，升级成会员折扣多多！"), nil
	}
	var discount float32
	switch ref_type {
	case REFTYPE_TACTIC:
		discount = coupon.Tactic
	case REFTYPE_REPORT:
		discount = coupon.Report
	case REFTYPE_COURSE:
		discount = coupon.Class
	case REFTYPE_STRATEGY:
		discount = coupon.Strategy
	// 升级会员无打折
	case REFTYPE_MEMBER_UPDATE:
		discount = 1
	default:
		return 1.0, fmt.Sprintf("本产品暂时不能享受折扣！"), nil
	}

	if groupWeight == MEMBER_GROUP_WEIGHT_VIP0 {
		comment = fmt.Sprintf("普通会员暂时不能享受折扣，升级成会员折扣多多！")
	} else {
		if discount == 0 {
			comment = fmt.Sprintf("%v会员，免费尊享", VIPLevel[groupWeight])
		} else if discount == 1 {
			comment = fmt.Sprintf("%v会员，暂时不能享受折扣", VIPLevel[groupWeight])
		} else {
			comment = fmt.Sprintf("%v会员，折扣：%1.1f折", VIPLevel[groupWeight], discount*10)
		}
	}
	return discount, comment, nil
}
